The present invention relates to an encoding device and an encoding method. More specifically, the present invention relates to an encoding device and an encoding method for changing a code amount of already compressed image data.
JPEG (Joint Photographic Experts Group) is an international image compression/expansion standard that is efficient for still images. In recent years, compressed image files compliant to the JPEG standard (hereinafter referred to as xe2x80x9cJPEG filesxe2x80x9d) have been widely used on the Internet, and the Internet users can easily download JPEG files. The Internet users can download the JPEG files and store them in a storage medium such as a hard disk or a memory.
In some cases, a user may wish to further reduce the size (code amount) of a downloaded JPEG file in view of the storage capacity of the storage medium. However, if the JPEG file has not been created by the user but has been obtained from a medium such as the Internet, the user does not have the uncompressed original image file. In such a case, it is necessary to first (1) produce recovered image data by performing an image expansion operation on the downloaded JPEG file, and then (2) compress the recovered image data at an increased compression rate.
Such an operation can be performed by using an image compression/expansion device as illustrated in FIG. 43 through a procedure as illustrated in FIG. 44.
First, compressed image data JPGDI stored in a code memory 7 is read out (ST201).
The read-out compressed image data JPGDI is separated by a separation circuit 8 into quantization step values DQT(D), code table information DHT(D) and variable-length codes CODE(D) (ST202).
The quantization step values DQT(D) are set in a quantization table 12, and the code table information DHT(D) is set in a code table 13 (ST203).
A variable-length decoding section 9c produces a run length RRRR(D)/size SSSS(D) combination from each variable-length code CODE(D), while extracting an additional bit string ADBIT(D) therefrom, based on the code table information set in the code table 13 (ST204).
A coefficient generation section 9b extracts an effective coefficient Sq(D) by using the size SSSS(D) and the additional bit string ADBIT(D) (ST205).
A run-length decoding section 9a produces a DCT coefficient ZZ(D) from the run length RRRR(D)/effective coefficient Sq(D) combination (ST206).
An inverse quantization section 10 inverse-quantizes each DCT coefficient ZZ(D) according to a corresponding quantization step value set in the quantization table 12 (ST207), and an inverse Discrete Cosine Transform (hereinafter referred to as xe2x80x9cDCTxe2x80x9d) section 11 further performs a two-dimensional inverse DCT on the obtained data (ST208). The results of the inverse DCT are sequentially written into an image memory 2 as recovered image data PXLDO (ST209).
After the recovered image data PXLDO is obtained by performing an image expansion operation on the compressed image data as described above, the obtained data is compressed again at an increased compression rate. In order to produce compressed image data of a high compression rate, the quantization step values are read out from the quantization table 12 through an external reading terminal 21 (ST211), changed to larger values, and then re-set in the quantization table 12 (ST212).
Then, recovered image data PXLDI is read out from the image memory 2 and input to a DCT section 3 (ST214).
The DCT section 3 performs a two-dimensional DCT operation to obtain DCT coefficients (ST215).
A quantization section 4 quantizes the DCT coefficients according to the quantization step values set in the quantization table 12 in step ST212 (ST216).
The quantized DCT coefficients ZZ(E) are sequentially supplied to, and run-length-encoded in, a run-length encoding section 5a in the order of zigzag scanning, thereby obtaining run length RRRR(E)/effective coefficient Sq(E) combinations (ST217).
A size/additional bit string generation section 5b assigns a size SSSS(E) and an additional bit string ADBIT(E) to each effective coefficient Sq(E) (ST218).
A variable-length encoding section 5c assigns a variable-length code to each run length RRRR(E)/size SSSS(E) combination based on the information set in the code table 13. The additional bit string ADBIT(E) assigned by the size/additional bit string generation section 5b is attached to the end of the variable-length code, thereby producing a variable-length code CODE(E) (ST219).
The variable-length code CODE(E) is assigned to the run length RRRR(E)/size SSSS(E) combination as described above.
A multiplexing circuit 6 multiplexes together the variable-length codes CODE(E), the quantization step values DQT(E) and the code table information DHT(E) to produce new compressed image data JPGDO (ST220).
If the code amount of the obtained compressed image data JPGDO is not of a desired size, the above-described image compression operation (ST221-ST212-ST221) is repeated while changing the quantization step values. Thus, it is possible to obtain compressed image data JPGDO having a desired code amount.
As described above, when changing the code amount of a compressed image with the conventional image compression/expansion device, it is necessary to perform all of the various image expansion operations (such as variable-length decoding, run-length decoding, inverse quantization, and inverse DCT) to produce a recovered image, change the quantization step values, and then perform all of the various image compression operations (such as DCT, quantization, run-length encoding, and variable-length encoding).
An object of the present invention is to provide an encoding device capable of efficiently changing the code amount(compression rate) of compressed image data.
According to one aspect of the present invention, there is provided an encoding device for changing a code amount of compressed image data which has been produced by performing a Discrete Cosine Transform (hereinafter referred to as xe2x80x9cDCTxe2x80x9d) operation, a quantization operation, a run-length encoding operation and a variable-length encoding operation on original image data, the encoding device including separation means, decoding means, a size conversion table, size conversion means, variable-length encoding means, and multiplexing means.
The separation means separates the compressed image data into variable-length codes, quantization step values and code table information. The code table information represents a correspondence between combinations of run length and size and code words. The decoding means decodes each of the variable-length codes from the separation means into a run length, a size and an additional bit string based on the code table information. A frequency region and a size conversion amount are set in the size conversion table. The size conversion means performs a conversion operation on the run length, the size and the additional bit string obtained by the decoding means based on the frequency region and the size conversion amount set in the size conversion table. The variable-length encoding means performs a variable-length encoding operation on the run length, the size and the additional bit string converted by the size conversion means based on the code table information. The multiplexing means multiplexes together variable-length codes obtained by the variable-length encoding means, the quantization step values and the code table information.
In the encoding device, the size conversion means changes the value of each size belonging to the frequency region set in the size conversion table among the sizes obtained by the decoding means by the size conversion amount set for the frequency region. Moreover, the size conversion means also changes the additional bit string and the run length according to the change in the size. Therefore, the code amount of a variable-length code obtained by the variable-length encoding means is different from the code amount of the variable-length code from the separation means. Thus, the code amount of the compressed image data which is obtained as a result of the multiplexing operation by the multiplexing means is different from the code amount of the compressed image data before being separated by the separation means.
As described above, the encoding device is provided with the size conversion table and the size conversion means, thereby eliminating the need to perform the operations required for recovering the original image (such as inverse quantization and inverse DCT) and the operations required for compressing the image (such as updating the quantization table, DCT, quantization, run-length encoding). Thus, it is possible to efficiently change the code amount of compressed image data.
Preferably, the encoding device further includes specification means. The specification means specifies a combination of run length and size to be converted. The size conversion means performs the conversion operation when the run length and the size obtained by the decoding means match the combination specified by the specification means.
There are some cases where the code length of a code word corresponding to a run length/size combination remains unchanged even if the size is changed for a particular frequency region by the size conversion means. In such a case, a significant effect of changing the code amount is not obtained. The quantization step values are multiplexed by the multiplexing means with the variable-length codes obtained by the variable-length encoding means and the code table information while only the quantization step values are left unchanged. Therefore, the image quality may deteriorate when an image recovery operation is performed on the compressed image data obtained by the multiplexing means. Thus, in some cases, the deterioration in the image quality may be significant while there is only a little effect of reducing the code amount.
In the encoding device, the specification means specifies, as a combination to be converted, a combination of run length and size for which a code amount changing effect can be obtained. The size conversion means performs the conversion operation when the run length and the size obtained by the decoding means match the combination specified by the specification means. Therefore, it is possible to suppress the deterioration in the image quality which may occur when an image recovery operation is performed on the compressed image data.
Preferably, the encoding device further includes changing means. The changing means changes the quantization step values based on the frequency region and the size conversion amount set in the size conversion table. The multiplexing means multiplexes together the quantization step values changed by the changing means, the variable-length codes obtained by the variable-length encoding means and the code table information.
As described above, when the quantization step values are multiplexed by the multiplexing means while they are left unchanged, the deterioration in the image quality may occur when an image recovery operation is performed on the obtained compressed image data.
In the encoding device, the changing means is provided, whereby the quantization step values are changed based on the frequency region and the size conversion amount set in the size conversion table. Then, the changed quantization step values are multiplexed by the multiplexing means. Therefore, it is possible to suppress the deterioration in the image quality which may occur when an image recovery operation is performed on the obtained compressed image data.
Preferably, the size conversion table includes a luminance component conversion table and a color difference component conversion table. A first frequency region and a first size conversion amount are set in the luminance component conversion table. A second frequency region and a second size conversion amount are set in the color difference component conversion table. The size conversion means converts each combination of run length, size and additional bit string for a luminance component among the run lengths, the sizes and the additional bit strings obtained by the decoding means based on the first frequency region and the first size conversion amount, and converts each combination of run length, size and additional bit string for a color difference component among the run lengths, the sizes and the additional bit strings obtained by the decoding means based on the second frequency region and the second size conversion amount.
Generally, human eyes are very sensitive to changes in the luminance component, but are relatively insensitive to changes in the color difference components.
In the encoding device, the size conversion table includes the luminance component conversion table and the color difference component conversion table. A small frequency region (the first frequency region) for which a conversion is to be performed and a small size conversion amount (the first size conversion amount) are set in the luminance component conversion table, and a large frequency region (the second frequency region) for which a conversion is to be performed and a large size conversion amount (the second size conversion amount) are set in the color difference component conversion table. In this way, it is possible to reduce the code amount in such a manner that the deterioration in the image quality due to the conversion is less perceivable by human eyes.
Preferably, the encoding device further includes a size memory. The size memory stores the run length, the size and the additional bit string obtained by the decoding means. The size conversion means converts the run length, the size and the additional bit string which are read out from the size memory based on the frequency region and the size conversion amount set in the size conversion table.
The run-lengths, the sizes and the additional bit strings are generated from the decoding means at irregular rates. However, the encoding device is provided with the size memory, whereby the run lengths, the sizes and the additional bit strings obtained by the decoding means can be continuously supplied to the size conversion means at a constant rate. Thus, it is possible to continuously perform the conversion operation by the size conversion means.
Preferably, the encoding device further includes a code memory and memory control means. The code memory stores compressed image data. The memory control means controls writing/reading of data to/from the size memory and the code memory. Specifically, the memory control means sets the code memory in a read mode and the size memory in a write mode when the size memory runs out of the run length, the size and the additional bit string to be read out there from, whereas the memory control means sets the size memory in the read mode and the code memory in the write mode when the size memory runs out of a space for writing the run length, the size and the additional bit string.
In the encoding device, the memory control means first controls the code memory in the read mode and the size memory in the write mode. Thus, compressed image data is read out from the code memory, and is subjected to the operation by the separation means and the operation by the decoding means. Then, the run lengths, the sizes and the additional bit strings obtained by the decoding means are written into the size memory.
Then, when the size memory runs out of a space for writing the run length, the size and the additional bit string, the memory control means controls the size memory in the read mode and the code memory in the write mode. Thus, the operation of reading out compressed image data from the code memory is stopped. The run lengths, the sizes and the additional bit strings which have been written into the size memory are read out from the size memory, and are subjected to the operation by the size conversion means, the operation by the variable-length encoding means and the operation by the multiplexing means. The results of the multiplexing operation are written into the code memory.
Then, when the size memory runs out of the run length, the size and the additional bit string to be read out therefrom, the memory control means controls the code memory in the read mode and the size memory in the write mode. Thus, the operation of reading out compressed image data from the code memory is resumed.
In this way, the series of decoding operations, including reading out compressed image data from the code memory, the operation by the separation means and the operation by the decoding means, and the series of encoding operations, including the operation by the size conversion means, the operation by the variable-length encoding means and the operation by the multiplexing means, can be alternately performed in a time division manner. Thus, it is not necessary to store all of the run lengths, sizes and additional bit strings for the entire compressed image data in the size memory. As a result, it is possible to reduce the capacity of the size memory.
According to another aspect of the present invention, there is provided an encoding device for changing a code amount of compressed image data which has been produced by performing a DCT operation, a quantization operation, a run-length encoding operation and a variable-length encoding operation on original image data, the encoding device including separation means, decoding means, coefficient generation means, a coefficient conversion table, coefficient conversion means, size/additional bit string generation means, variable-length encoding means and multiplexing means.
The separation means separates the compressed image data into variable-length codes, quantization step values and code table information. The code table information represents a correspondence between combinations of run length and size and code words. The decoding means decodes each of the variable-length codes from the separation means into a run length, a size and an additional bit string based on the code table information. The coefficient generation means specifies an effective coefficient based on the size and the additional bit string obtained by the decoding means. A frequency region and a coefficient conversion amount are set in the coefficient conversion table. The coefficient conversion means performs a conversion operation on the run length obtained by the decoding means and the effective coefficient specified by the coefficient generation means based on the frequency region and the coefficient conversion amount set in the coefficient conversion table. The size/additional bit string generation means assigns a size and an additional bit string to the effective coefficient converted by the coefficient conversion means. The variable-length encoding means performs a variable-length encoding operation on the run length converted by the coefficient conversion means and the size and the additional bit string assigned by the size/additional bit string generation means based on the code table information. The multiplexing means multiplexes together variable-length codes obtained by the variable-length encoding means, the quantization step values and the code table information.
In the encoding device, the coefficient conversion means changes the value of each effective coefficient belonging to the frequency region set in the coefficient conversion table among the effective coefficients obtained by the coefficient generation means by the coefficient conversion amount set for the frequency region. Moreover, the coefficient conversion means also changes the run length according to the change in the effective coefficient. Therefore, the size and the additional bit string assigned by the size/additional bit string generation means are different from the size and the additional bit string obtained by the decoding means. Moreover, the code amount of a variable-length code obtained by the variable-length encoding means is different from the code amount of the variable-length code from the separation means. As a result, the code amount of the compressed image data which is obtained as a result of the multiplexing operation by the multiplexing means is different from the code amount of the compressed image data before being separated by the separation means.
As described above, the encoding device is provided with the coefficient conversion table and the coefficient conversion means, thereby eliminating the need to perform the operations required for recovering the original image (such as inverse quantization and inverse DCT) and the operations required for compressing the image (such as updating the quantization table, DCT, quantization, run-length encoding). Thus, it is possible to efficiently change the code amount of compressed image data.
Preferably, the encoding device further includes specification means. The specification means specifies a combination of run length and effective coefficient to be converted. The coefficient conversion means performs the conversion operation when the run length obtained by the decoding means and the effective coefficient specified by the coefficient generation means match the combination specified by the specification means.
There are some cases where the code length of a code word corresponding to a run length/size combination remains unchanged even if the value of an effective coefficient in a particular frequency region is changed by the coefficient conversion means. In such a case, a significant effect of changing the code amount is not obtained. The quantization step values are multiplexed by the multiplexing means with the variable-length codes obtained by the variable-length encoding means and the code table information while only the quantization step values are left unchanged. Therefore, the image quality may deteriorate when an image recovery operation is performed on the compressed image data which is obtained as a result of the multiplexing operation by the multiplexing means. Thus, in some cases, the deterioration in the image quality may be significant while there is only a little effect of changing the code amount.
In the encoding device, the specification means specifies, as a combination to be converted, a combination of run length and effective coefficient for which a code amount changing effect can be obtained. Moreover, the coefficient conversion means performs the conversion operation when the run length obtained by the decoding means and the effective coefficient specified by the coefficient generation means match the combination specified by the specification means. Therefore, it is possible to suppress the deterioration in the image quality which may occur when an image recovery operation is performed on compressed image data.
Preferably, the encoding device further includes changing means. The changing means changes the quantization step values based on the frequency region and the coefficient conversion amount set in the coefficient conversion table. The multiplexing means multiplexes together the quantization step values changed by the changing means, the variable-length codes obtained by the variable-length encoding means and the code table information.
As described above, in a case where the multiplexing operation is performed by the multiplexing means while the quantization step values are left unchanged, deterioration in the image quality may occur when an image recovery operation is performed on the obtained compressed image data.
The encoding device is provided with the changing means, whereby the quantization step values are changed based on the frequency region and the coefficient conversion amount set in the coefficient conversion table. Then, the changed quantization step values are multiplexed by the multiplexing means. Therefore, it is possible to suppress the deterioration in the image quality which may occur when an image recovery operation is performed on the obtained compressed image data.
Preferably, the coefficient conversion table includes a luminance component conversion table and a color difference component conversion table. A first frequency region and a first coefficient conversion amount are set in the luminance component conversion table. A second frequency region and a second coefficient conversion amount are set in the color difference component conversion table. The coefficient conversion means converts each combination of run length and effective coefficient for a luminance component among the run lengths obtained by the decoding means and the effective coefficients specified by the coefficient generation means based on the first frequency region and the first coefficient conversion amount, and converts each combination of run length and effective coefficient for a color difference component among the run lengths obtained by the decoding means and the effective coefficients specified by the coefficient generation means based on the second frequency region and the second coefficient conversion amount.
Generally, human eyes are very sensitive to changes in the luminance component, but are relatively insensitive to changes in the color difference components.
In the encoding device, the coefficient conversion table includes the luminance component conversion table and the color difference component conversion table. A small frequency region (the first frequency region) for which a conversion is to be performed and a small coefficient conversion amount (the first coefficient conversion amount) are set in the luminance component conversion table, and a large frequency region (the second frequency region) for which a conversion is to be performed and a large coefficient conversion amount (the second coefficient conversion amount) are set in the color difference component conversion table. In this way, it is possible to reduce the code amount in such a manner that the deterioration in the image quality due to the conversion is less perceivable by human eyes.
Preferably, the encoding device further includes a coefficient memory. The coefficient memory stores the run length obtained by the decoding means and the effective coefficient specified by the coefficient generation means. The coefficient conversion means converts the run length and the effective coefficient which are read out from the coefficient memory based on the frequency region and the coefficient conversion amount set in the coefficient conversion table.
The run-lengths from the decoding means and the effective coefficients from the coefficient generation means are generated at irregular rates. However, the encoding device is provided with the coefficient memory, whereby the run lengths obtained by the decoding means and the effective coefficients from the coefficient generation means can be continuously supplied to the coefficient conversion means at a constant rate. Thus, it is possible to continuously perform the conversion operation by the coefficient conversion means.
Preferably, the encoding device further includes a code memory and memory control means. The code memory stores compressed image data. The memory control means controls writing/reading of data to/from the coefficient memory and the code memory. Specifically, the memory control means set the code memory in a read mode and the coefficient memory in a write mode when the coefficient memory runs out of the run length and the effective coefficient to be read out therefrom, whereas the memory control means sets the coefficient memory in the read mode and the code memory in the write mode when the coefficient memory runs out of a space for writing the run length and the effective coefficient.
In the encoding device, the memory control means first controls the code memory in the read mode and the coefficient memory in the write mode. Thus, compressed image data is read out from the code memory, and is subjected to the operation by the separation means, the operation by the decoding means and the operation by the coefficient generation means. Then, the run lengths obtained by the decoding means and the effective coefficients obtained by the coefficient generation means are written into the coefficient memory.
Then, when the coefficient memory runs out of a space for writing the run length and the effective coefficient, the memory control means controls the coefficient memory in the read mode and the code memory in the write mode. Thus, the operation of reading out compressed image data from the code memory is stopped. The run lengths and the effective coefficients which have been written into the coefficient memory are read out from the coefficient memory, and are subjected to the operation by the coefficient conversion means, the operation by the size/additional bit string generation means, the operation by the variable-length encoding means and the operation by the multiplexing means. The results of the operation by the multiplexing means are written into the code memory.
Then, when the coefficient memory runs out of the run length and the effective coefficient to be read out therefrom, the memory control means controls the code memory in the read mode and the coefficient memory in the write mode. Thus, the operation of reading out compressed image data from the code memory is resumed.
In this way, the series of decoding operations, including reading out compressed image data from the code memory, the operation by the separation means, the operation by the decoding means and the operation by the coefficient generation means, and the series of encoding operations, including the operation by the coefficient conversion means, the operation by the size/additional bit string generation means, the operation by the variable-length encoding means and the operation by the multiplexing means, can be alternately performed in a time division manner. Thus, it is not necessary to store all of the run lengths and the effective coefficients for the entire compressed image data in the coefficient memory. As a result, it is possible to reduce the capacity of the coefficient memory.
According to still another aspect of the present invention, there is provided an encoding method for changing a code amount of compressed image data which has been produced by performing a DCT operation, a quantization operation, a run-length encoding operation and a variable-length encoding operation on original image data, the encoding method including a separation step, a decoding step, a setting step, a conversion step, a variable-length encoding step and a multiplexing step.
In the separation step, the compressed image data is separated into variable-length codes, quantization step values and code table information. The code table information represents a correspondence between combinations of run length and size and code words. In the decoding step, each of the variable-length codes is decoded into a run length, a size and an additional bit string based on the code table information. In the setting step, a frequency region and a size conversion amount are set. In the conversion step, a conversion operation is performed on the run length, the size and the additional bit string obtained in the decoding step based on the frequency region and the size conversion amount which have been set. In the variable-length encoding step, a variable-length encoding operation is performed on the run length, the size and the additional bit string converted in the conversion step based on the code table information. In the multiplexing step, variable-length codes obtained in the variable-length encoding step, the quantization step values and the code table information are multiplexed together.
Moreover, in the encoding method, if a code amount of compressed image data obtained in the multiplexing step is not a desired value, the frequency region and/or the size conversion amount set in the setting step are/is changed, and the conversion step, the variable-length encoding step and the multiplexing step are performed again.
In the encoding method, the value of each size belonging to the frequency region which has been set among the sizes obtained in the decoding step is changed in the conversion step by the size conversion amount set for the frequency region. Moreover, the additional bit string and the run length are also changed according to the change in the size. Therefore, the code amount of a variable-length code obtained in the variable-length encoding step is different from the code amount of the variable-length code obtained in the separation step. Thus, the code amount of the compressed image data which is obtained as a result of the multiplexing operation in the multiplexing step is different from the code amount of the compressed image data before being separated in the separation step.
Then, if the code amount of the compressed image data obtained in the multiplexing step is not a desired value, the frequency region and/or the size conversion amount set in the setting step are/is changed.
For example, when the code amount of the produced compressed image data is greater than the desired value, the size of the frequency region is increased, whereas when it is less than the desired value, the size of the frequency region is reduced. Similarly for the size conversion amount, when the code amount is greater than the desired value, the size conversion amount is increased, whereas when the code amount is less than the desired value, the size conversion amount is reduced. The setting can be changed by increasing or reducing either or both of the size of the frequency region and the size conversion amount.
After changing the setting, the conversion step, the variable-length encoding step and the multiplexing step are performed again.
As described above, in the encoding method, the conversion step, the variable-length encoding step and the multiplexing step are repeated while changing the frequency region and/or the size conversion amount until the code amount of the produced compressed image data is a desired value. Thus, it is possible to obtain compressed image data having a desired code amount.
According to still another aspect of the present invention, there is provided an encoding method for changing a code amount of compressed image data which has been produced by performing a DCT operation, a quantization operation, a run-length encoding operation and a variable-length encoding operation on original image data, the encoding method including: a separation step, a decoding step, a specification step, a setting step, a conversion step, an assignment step, a variable-length encoding step and a multiplexing step.
In the separation step, the compressed image data is separated into variable-length codes, quantization step values and code table information. The code table information represents a correspondence between combinations of run length and size and code words. In the decoding step, each of the variable-length codes is decoded into a run length, a size and an additional bit string based on the code table information. In the specification step, an effective coefficient is specified based on the size and the additional bit string obtained in the decoding step. In the setting step, a frequency region and a coefficient conversion amount are set. In the conversion step, the run length obtained in the decoding step and the effective coefficient specified by the specification step are converted based on the frequency region and the coefficient conversion amount which have been set. In the assignment step, a size and an additional bit string are assigned to the effective coefficient converted in the conversion step. In the variable-length encoding step, a variable-length encoding operation is performed on the run length converted in the conversion step and the size and the additional bit string assigned in the assignment step based on the code table information. In the multiplexing step, variable-length codes obtained in the variable-length encoding step, the quantization step values and the code table information are multiplexed together.
Moreover, in the encoding method, if a code amount of compressed image data obtained in the multiplexing step is not a desired value, the frequency region and/or the coefficient conversion amount set in the setting step are/is changed, and the conversion step, the assignment step, the variable-length encoding step and the multiplexing step are performed again.
In the encoding method, the value of each effective coefficient belonging to the frequency region which has been set among the effective coefficients obtained in the specification step is changed in the conversion step by the coefficient conversion amount set for the frequency region. Moreover, the run length is also changed according to the change in the effective coefficient. Therefore, the size and the additional bit string assigned in the assignment step are different from the size and the additional bit string obtained in the decoding step. Moreover, the code amount of a variable-length code obtained in the variable-length encoding step is different from the code amount of the variable-length code obtained in the separation step. As a result, the code amount of the compressed image data which is obtained as a result of the multiplexing operation in the multiplexing step is different from the code amount of the compressed image data before being separated in the separation step.
Then, if the code amount of the compressed image data obtained in the multiplexing step is not a desired value, the frequency region and/or the coefficient conversion amount set in the setting step are/is changed.
For example, when the code amount of the newly produced compressed image data is greater than the desired value, the size of the frequency region is increased, whereas when it is less than the desired value, the size of the frequency region is reduced. Similarly for the coefficient conversion amount, when the code amount is greater than the desired value, the coefficient conversion amount is increased, whereas when the code amount is less than the desired value, the coefficient conversion amount is reduced. The setting can be changed by increasing or reducing either or both of the size of the frequency region and the coefficient conversion amount.
After changing the setting, the conversion step, the assignment step, the variable-length encoding step and the multiplexing step are performed again.
As described above, in the encoding method, the conversion step, the assignment step, the variable-length encoding step and the multiplexing step are repeated while changing the frequency region and/or the coefficient conversion amount until the code amount of the produced compressed image data is a desired value. Thus, it is possible to obtain compressed image data having a desired code amount.